package com.spring.cloud.test.ribbon;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  ribbo 自定规则
 * </p>
 *
 * @author zql
 * @date 2018/5/17 15:26
 */
public class T {

    public static void main(String[] args) {
        BaseLoadBalancer lb = new BaseLoadBalancer();

        MyRule rule = new MyRule();
        rule.setLoadBalancer(lb);
        lb.setRule(rule);

        List<Server> servers = new ArrayList<Server>();
        servers.add(new Server("localhost", 8080));
        servers.add(new Server("localhost", 8081));
        servers.add(new Server("localhost", 8082));

        lb.addServers(servers);

        for(int i=0; i < 10; i++){
            Server s = lb.chooseServer(null);
            System.out.println(s);
        }
    }
}
